package conexion;

import java.sql.*;

public class bd_odbc_jdbc {

    String url_JDBC,url_ODBC,login,password;

    public bd_odbc_jdbc()
        {
            url_ODBC = "jdbc:odbc:mysql_is2-sqlin";
            url_JDBC="jdbc:mysql://localhost:3306/is2-sqli1";
            login="root";
            password="admin";
        }

    public Connection crearConexionODBC()
        {
         Connection c = null;
         try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                //Class.forName("com.mysql.jdbc.Driver").newInstance();
            }
            catch (ClassNotFoundException cnfe){System.out.println("Clase no encontrada");}
            catch (Exception e){System.out.println("Clase no encontrada");}

         try
            {
                //c = DriverManager.getConnection (url_JDBC,login,password);
                c = DriverManager.getConnection(url_ODBC,login,password);
            }
            catch(Exception e)
            {
                System.out.println("Error, url, login o contraseña incorrecta");
                System.out.println(e.toString());
            }
		return c;

        }

    public Connection crearConexionJDBC()
        {
         Connection c = null;
         try
            {
                //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Class.forName("com.mysql.jdbc.Driver").newInstance();
            }
            catch (ClassNotFoundException cnfe){System.out.println("Clase no encontrada");}
            catch (Exception e){System.out.println("Clase no encontrada");}

         try
            {
                c = DriverManager.getConnection (url_JDBC,login,password);
                //c = DriverManager.getConnection(url_ODBC,login,password);
            }
            catch(Exception e)
            {
                System.out.println("Error, url, login o contraseña incorrecta");
                System.out.println(e.toString());
            }
		return c;

        }

    public void cerrarConexion(Connection c)
    {
        try
         {
          c.close();
         }
     catch (Exception e){e.toString();}
    }


}
